<template>
  <div class="main">
    <div class="showBox">
      <div class="title">
        <span>开始游戏</span>
        <img src="../../../static/image/showClose.png" alt="" @click="$router.push({path:'/seed/2'})">
      </div>
      <div class="number">
        <span>{{arr[id-1]}}种子：</span>
        <input type="text" :placeholder="'请输入'+arr[id-1]+'种子数量'" v-model="seed" @focus='message="温馨提示： 为了更好的游戏体验，亲您的充值还请小于4000枚哦"'>
      </div>
      <div class="tips">
        <p>{{message}}</p>
      </div>
      <div class="imgs">
        <img src="../../../static/image/X-btn.png" alt="" @click="$router.push({path:'/seed/2'})">
        <img src="../../../static/image/Accept-btn.png" alt="" @click="changePage">
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "digPopup",
  data() {
    return {
      id: this.$route.params.id,
      // name: this.$route.query.id,
      arr: ["金", "银", "铜"],
      seed: "",
      jin: null,
      yin: null,
      tong: null,
      username: "",
      activityId: null,
      flag: true,
      message: "温馨提示： 为了更好的游戏体验，亲您的充值还请小于4000枚哦"
      // ...this.$route.query
    };
  },
  created() {
    let exchange = JSON.parse(localStorage.getItem("exchange"));
    this.exchange = exchange;
    this.username = u.getStore("user").name;
    this.jin = u.getStore("userInfo").seeds_amount;
    this.yin = u.getStore("userInfo").silver_seeds_amount;
    this.tong = u.getStore("userInfo").copper_seeds_amount;
    this.$parent.flag1 = false;
    this.$parent.flag2 = false;
  },
  mounted() {
    u.findActivityStatus({ type: this.id }, data => {
      this.activityId = data[0].data.activity.id;
      localStorage.setItem("gamdId", this.activityId);
      // console.log(activityId);
    });
  },
  methods: {
    back() {
      history.back();
    },
    changePage() {
      if (!this.flag) {
        return;
      }

      if (this.id == 1) {
        if (this.seed <= this.jin && this.seed > 0 && this.seed <= 4000) {
          this.flag = false;
          u.playGame(
            {
              // activityId: this.activityId,
              activityId: u.getStore("gamdId"),
              seedNum: this.seed,
              type: 1,
              username: this.username
            },
            data => {
              this.flag = true;
              // if (data[0].data.count <= this.seed) {
              //   alert("剩余票券数为" + data[0].data.count);
              // } else {
              //   this.$router.push({
              //     path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
              //   });
              // }

              if (data[0].code == 200) {
                this.$router.push({
                  path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
                });
              } else if (data[0].code == 2012) {
                this.message = "剩余票券数为" + data[0].data.count;
              } else {
                this.message = data[0].message;
              }
            }
          );
        } else {
           this.message =
            "输入错误请重新输入，充值还请在0~4000枚，不得大于拥有数量";
          this.seed = 0;
        }
      }
      if (this.id == 2) {
        if (this.seed <= this.yin && this.seed > 0 && this.seed <= 4000) {
          this.flag = false;
          u.playGame(
            {
              activityId: this.activityId,
              seedNum: this.seed,
              type: 2,
              username: this.username
            },
            data => {
              this.flag = true;
              // if (data[0].data.count <= this.seed) {
              //   alert("剩余票券数为" + data[0].data.count);
              // } else {
              //   this.$router.push({
              //     path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
              //   });
              // }
              if (data[0].code == 200) {
                this.$router.push({
                  path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
                });
              } else if (data[0].code == 2012) {
                this.message = "剩余票券数为" + data[0].data.count;
              } else {
                this.message = data[0].message;
              }
              // }
            }
          );
        } else {
           this.message =
            "输入错误请重新输入，充值还请在0~4000枚，不得大于拥有数量";
          this.seed = 0;
        }
      }
      if (this.id == 3) {
        if (this.seed <= this.tong && this.seed > 0 && this.seed <= 4000) {
          this.flag = false;
          u.playGame(
            {
              activityId: this.activityId,
              seedNum: this.seed,
              type: 3,
              username: this.username
            },
            data => {
              this.flag = true;
              // if (data[0].data.count <= this.seed) {
              //   alert("剩余票券数为" + data[0].data.count);
              //   console.log(data.code)
              // } else if (data.code == 200) {
              //   this.$router.push({
              //     path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
              //   });
              // }
              if (data[0].code == 200) {
                this.$router.push({
                  path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
                });
              } else if (data[0].code == 2012) {
                this.message = "剩余票券数为" + data[0].data.count;
              } else {
                this.message = data[0].message;
              }
            }
          );
        } else {
          this.message =
            "输入错误请重新输入，充值还请在0~4000枚，不得大于拥有数量";
          this.seed = 0;
        }
      }
      // if (this.seed > 0 && this.seed < 4000) {
      //   this.$router.push({
      //     path: "/digSuccess/" + this.seed + "|" + this.arr[this.id - 1]
      //   });
      // } else {
      //   alert("亲您的充值还请在0~4000枚之间哦");
      //   this.seed = 0;
      // }
    }
  }
};
</script>
<style scoped>
/* @import url("../../css/base.css"); */
.main {
  width: 100vw;
  height: 100vh;
  background: url("../../../static/image/ginsengbg2.png") no-repeat center;
  background-size: 100% 100%;
  padding-top: 50%;
}
.showBox {
  width: 443px;
  height: 282px;
  background: url("../../../static/image/showWin.png") no-repeat center;
  background-size: 100% 100%;
  margin: 0 auto;
  padding: 40px 25px;
}
.showBox .title,
.showBox .number {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.showBox .title span {
  font-size: 22px;
  color: #ffffff;
  font-weight: bold;
  text-shadow: 0 2px #8d4707, 2px 0 #8d4707, -2px 0 #8d4707, 0 -1px #8d4707;
}
.showBox .title img {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.showBox .number {
  margin-top: 50px;
  margin-bottom: 5px;
}
.showBox .number span {
  height: 18px;
  color: #ffffff;
  text-shadow: 0 2px #3a230a, 2px 0 #3a230a, -2px 0 #3a230a, 0 -1px #3a230a;
  font-weight: bold;
}
.showBox .number input {
  background: url("../../../static/image/bpxnumber.png") no-repeat center;
  background-size: 100% 100%;
  width: 323px;
  height: 43px;
  padding-left: 6%;
  margin-top: -3%;
}
.showBox .number input::-webkit-input-placeholder {
  color: #f1e0c8;
  font-weight: bold;
  text-shadow: 0 2px #bd8848, 2px 0 #bd8848, -2px 0 #bd8848, 0 -1px #bd8848;
  /* text-shadow: -2px 2px 0px #9f6946, -2px -1px 3px #9f6946; */
  /* text-shadow: px 2px 2px #bd8848; */
}
.showBox .tips {
  width: 100%;
  display: flex;
  flex-direction: row;
  /* justify-content: flex-end; */
  padding-left: 20%;
  margin-bottom: 45px;
  height: 40px;
}
.showBox .tips p {
  font-size: 14px;
  color: #ffffff;
  text-shadow: 0 1px #a76d30, 1px 0 #a76d30, -1px 0 #a76d30, 0 -1px #a76d30;
}
.showBox .imgs {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  position: relative;
  top: 20px;
}
.showBox .imgs img {
  cursor: pointer;
}
</style>

